package com.isunland.managesystem.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.GuideMenuOriginal;
import com.isunland.managesystem.entity.GuideMenuOriginal.ChildGuideMenuContent;
import com.isunland.managesystem.entity.GuideMenuOriginal.SuperGuideMenuContent;
import java.util.ArrayList;

public class SuperTreeViewAdapter extends BaseExpandableListAdapter {

  private ArrayList<SuperGuideMenuContent> mSuperList =
      new ArrayList<GuideMenuOriginal.SuperGuideMenuContent>();
  private ArrayList<ChildGuideMenuContent> mChildList =
      new ArrayList<GuideMenuOriginal.ChildGuideMenuContent>();
  private LayoutInflater inflater;
  private Context context;

  public SuperTreeViewAdapter(Context context,
      ArrayList<GuideMenuOriginal.SuperGuideMenuContent> mSuperList) {
    this.mSuperList = mSuperList;
    this.context = context;
    this.inflater = LayoutInflater.from(context);
  }

  @Override public int getGroupCount() {

    return mSuperList.size();
  }

  @Override public int getChildrenCount(int groupPosition) {
    if (mSuperList.size() > 0) {

      return mSuperList.get(groupPosition).getChildren().size();
    } else {
      return 0;
    }
  }

  @Override public Object getGroup(int groupPosition) {

    return mSuperList.get(groupPosition);
  }

  @Override public Object getChild(int groupPosition, int childPosition) {

    return mSuperList.get(groupPosition).getChildren().get(childPosition);
  }

  @Override public long getGroupId(int groupPosition) {
    return groupPosition;
  }

  @Override public long getChildId(int groupPosition, int childPosition) {
    return childPosition;
  }

  @Override public boolean hasStableIds() {

    return true;
  }

  @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
      ViewGroup parent) {

    if (convertView == null) {
      convertView = inflater.inflate(R.layout.exlist_item_super, parent, false);
    }

    TextView tvchild = (TextView) convertView.findViewById(R.id.tv_child);
    if (TextUtils.isEmpty(mSuperList.get(groupPosition).getMobileResName())) {
      tvchild.setText("默认");
    } else {
      tvchild.setText(mSuperList.get(groupPosition).getMobileResName());
    }

    return convertView;
  }

  @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
      View convertView, ViewGroup parent) {

    if (convertView == null) {
      convertView = inflater.inflate(R.layout.exlist_item_child, parent, false);
    }

    TextView tvchild = (TextView) convertView.findViewById(R.id.tv_child);
    tvchild.setText(
        mSuperList.get(groupPosition).getChildren().get(childPosition).getMobileResName());

    return convertView;
  }

  @Override public boolean isChildSelectable(int groupPosition, int childPosition) {

    return true;
  }

  @Override public boolean isEmpty() {

    return false;
  }
}
